<?php
//global $thongso;
//echo $thongso;die();
//viewData();
//function abcdef(){

//return $objResponse->getXML();
//}

$objXajax->registerFunction('frmusersInit');
function frmusersInit(){ //xajax_frmusers_Init
  global $objDbSelect,$lang,$userid,$powerid,$powertypeid;
     $objResponse = new xajaxResponse();
     $cbbPowerType = createCbbPowerType($powertypeid,'frmuser_cbbPowerType','xajax_loadPower(this.value)'); // lấy chuổi combobox cho loại Quyền
    // echo 'aaa';
     $objResponse->addAssign('tdPowertype', 'innerHTML',$cbbPowerType);
     return $objResponse->getXML();   
}

/*
* Hàm dùng để tạo chuổi combobox cho loại quyền.
* @param 1 : $powertypeid - Loại quyền của user đăng nhập
* @param 2 : tên hàm đ 
*/
function createCbbPowerType($powertypeid,$id,$onChangeFunc='',$all=false){
    global $objDbSelect,$lang;
    $condition = '';
    $powertypeid =1;
    switch($powertypeid){
       case POWER_MASTER : $condition = ' and (id = '.POWER_SUPERVISOR. ' or id = ' .POWER_ACCOUNT. ' or id = ' .POWER_AGENCY.')'; break;
       case POWER_SUPERVISOR : $condition = ' and (id = ' .POWER_ACCOUNT. ' or id = ' .POWER_AGENCY.')'; break;
       case POWER_AGENCY : $condition = 'and (id = '.POWER_CUSTOMER. ' or id = ' .POWER_CUSTOMER_DEMO. ' or id = ' .POWER_MANAGER_CUSTOMER.')'; break;
       default : $condition = ' and 1 = 0'; break;
    }
    $sql =  "select id as id, name_$lang as name from tbl_power_type where active = 1 $condition ";
   // echo $sql;die();
    $arr = $objDbSelect->GetArray($sql);
    $strResult = '';
    for($i=0;$i<count($arr);$i++){
        $value = $arr[$i]['id'];
        $name =  $arr[$i]['name'];
        $strResult .= "<option value ='$value'>$name</option>";
    }
    $addFunction ='';    
    if($onChangeFunc!=''){
        $addFunction = "onchange='$onChangeFunc'";
    }
    $firstOption = '';
    if($all){
      $firstOption = "<option value ='' > Tất cả </option> "; 
    }else{
      $firstOption = "<option value ='-1' > Chọn </option> ";   
    }
    $strResult ="<select id='$id' $addFunction>$firstOption".$strResult.'</select>';  
   // echo ''
    return   $strResult;
}
function init_testtab(){
 $objResponse = new xajaxResponse();
$objResponse->addScript("$('#txtAddUsername').val('aaaaaaaaaaaa');");
return $objResponse->getXML();   
}
function viewData(){
//$objResponse = new xajaxResponse();
$objResponse = new xajaxResponse();
$objResponse->addScript("$('#txtAddUsername').val('aaaaaaaaaaaa');");
$objResponse->addAlert('abcdef');
 return $objResponse->getXML();
}

 
//$objResponse->addAlert('vaoduocmoighe');
//function callalert(){
//    $objResponse = new xajaxResponse();
//    $objResponse->addAlert('colenao');
//    return $objResponse->getXML();
//}
?>
